package com.yao2san.sim.framework.utils;

import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

import java.util.List;

public class WebUtil {
    private static final PathMatcher PATH_MATCHER = new AntPathMatcher();

    public static boolean mathUrl(String urlPattern, String url) {
        return PATH_MATCHER.match(urlPattern, url);
    }

    public static boolean mathUrl(String[] urlPatterns, String url) {
        if (urlPatterns == null) {
            throw new NullPointerException("urlPatterns can't be null");
        }
        for (String urlPattern : urlPatterns) {
            if (PATH_MATCHER.match(urlPattern, url)) {
                return true;
            }
        }
        return false;
    }
    public static boolean mathUrl(List<String> urlPatterns, String url) {
        if (urlPatterns == null) {
            throw new NullPointerException("urlPatterns can't be null");
        }
        for (String urlPattern : urlPatterns) {
            if (PATH_MATCHER.match(urlPattern, url)) {
                return true;
            }
        }
        return false;
    }
}
